package com.lightsaber.trade.as.dao.param;

import java.util.List;

import org.hibernate.SQLQuery;
import org.springside.modules.orm.Page;

import com.lightsaber.trade.as.entity.param.ProductType;
import com.lightsaber.trade.as.entity.reta.Product;
import com.lightsaber.trade.core.dao.BaseDao;

public class ProductTypeDao extends BaseDao<ProductType, String> {

    public List<ProductType> findByCategory(String category) {
        eq("category", category);
        
        return list();
    }
    
    @SuppressWarnings("unchecked")
    public String[] findAllCategoryDistinct(){
        String sql="select distinct category from reta_product_type";
        SQLQuery q= getSession().createSQLQuery(sql);
        
        List<Object[]> results=(List<Object[]> )q.list();
        String[] categories=new String[results.size()];
        for (int i=0;i<results.size();i++) {
            categories[i]=(String)results.get(i)[0];
        }
        
        return categories;
    }

    public void findPage(ProductType productType, Page<ProductType> page) {
        eq("category", productType.getCategory());
        
        findPage(page);
    }
}
